package cn.study.vue_project_xxx.service.impl;

import cn.study.vue_project_xxx.common.exception.KnowException;
import cn.study.vue_project_xxx.entity.dto.TAdminRoleDTO;
import cn.study.vue_project_xxx.entity.po.TAdminRole;
import cn.study.vue_project_xxx.manager.TadminRoleManager;
import cn.study.vue_project_xxx.util.PageParam;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.study.vue_project_xxx.mapper.TAdminRoleMapper;
import cn.study.vue_project_xxx.service.TAdminRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * (TAdminRole)表服务实现类
 *
 * @author makejava
 * @since 2023-04-25 09:53:59
 */
@Service("tAdminRoleService")
public class TAdminRoleServiceImpl extends ServiceImpl<TAdminRoleMapper, TAdminRole> implements TAdminRoleService {


    @Resource
    TadminRoleManager tadminRoleManager;


    @Override
    public Boolean addAdminRole(TAdminRole adminRole) {
        //校验参数
        if (Objects.isNull(adminRole)){
            throw new KnowException("无法获取到当前管理员的角色信息！");
        }
        //增加管理员角色
        return tadminRoleManager.addAdminRole(adminRole);
    }

    /*
    * 修改管理员角色
    * */
    @Override
    public Boolean updateAdminRole(TAdminRole adminRole) {
        //校验参数
        if (Objects.isNull(adminRole)){
            throw new KnowException("修改后的数据为空！");
        }
        //修改管理员角色
        return tadminRoleManager.updateAdminRole(adminRole);
    }

    /*
    * 批量删除管理员的角色
    * */
    @Override
    public Boolean deleteAdminRole(List<Integer> roleId) {
        //校验参数
        if (Objects.isNull(roleId)){
            throw new KnowException("得不到想要删除的角色！");
        }
        return tadminRoleManager.deleteAdminRole(roleId);
    }

    /*
    * 查询该管理员的角色列表
    * */
    @Override
    public Page<TAdminRole> selectAdminRole(Integer adminId, Page<TAdminRole> pageParam) {
        //校验参数
        if (Objects.isNull(adminId)){
            throw new KnowException("得不到当前登录管理员信息！");
        }
        return tadminRoleManager.selectAdminRole(adminId,pageParam);
    }
}

